package com.shujia.spark.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo7Filter {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()

    conf.setAppName("filter")

    conf.setMaster("local")

    val sc = new SparkContext(conf)


    val rdd1: RDD[Int] = sc.parallelize(List(1, 2, 3, 4, 5, 6, 7, 8, 9))

    /**
      * filter算子： 对数据进行过滤，函数返回treu保留数据，函数返回false过滤数据
      *
      */

    val filterRDD: RDD[Int] = rdd1.filter((i: Int) => {
      //保留偶数
      i % 2 == 0
    })

    filterRDD.foreach(println)

  }

}
